<?php


	namespace Midi\Event;
	
	use \Midi\Event;
	use \Midi\Util\Util;
	
	class SystemExclusiveEvent implements Event {
		
		protected $data;
		
		protected $length;
		
		public function __construct(array $data) {
			$this->length = count($data);
			$this->data   = $data;
		}
		
		public function getLength() {
			$lengthOfDelta = strlen(Util::getDeltaByteSequence($this->length));
			
			return 1 + $lengthOfDelta + $this->length;
		}
		
		public function __toString() {
			return EventType::getEventName($this->getType()) . ': manufacturer dependent';
		}
		
		public function toBinary() {
			$delta = Util::getDeltaByteSequence($this->length);
			return Util::pack($this->getType()) . $delta . implode('', $this->data);
		}
		
		public function isDivided() {
			return !$this->isNormal();
		}
		
		public function isNormal() {
			$byte = end($this->data);
			reset($this->data);
			return $byte === Util::pack(0xF7);
		}
		
		public function getData() {
			return $this->data;
		}
		
		public function getType() {
			return EventType::SYSTEM_EXCLUSIVE;
		}
		
	}

?>